<template>
  <div class="drawer_box">
    <!-- <div class="drawer_text" style="margin-bottom: 10px;">{{ CriminalInfoSelectText }}</div> -->
    <div
      class="flex_end_start"
      style="transform: translate(-1px, 1px); margin-bottom: 10px"
    >
      <!-- <div>
        <el-select
          v-model="selectValue"
          placeholder="监区"
          style="width: 200px; margin-right: 90px"
        >
          <el-option
            v-for="item in optionsS"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </div> -->
      <div style="display: flex">
      <div>
        <el-select
          v-model="cylevelValue"
          placeholder="处遇等级"
          style="width: 200px; margin-right: 40px"
        >
          <el-option
            v-for="item in optionsS"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </div>
        
        <el-input
          v-model="searchName"
          placeholder="请输入查询姓名"
          class="filter-item"
          style="margin-left: 10px; width: 200px"
        />
        <el-button
          title="查询"
          class="filter-item"
          style="margin-left: 10px"
          type="primary"
          :icon="Search"
          @click="getCriminalInfoSelect"
        >
        </el-button>
      </div>
    </div>
    <div class="isTable flex_start_start">
      <div class="btn_box">
          <div @click="btnClick(item,index)" :class="{isAtv:isIndex == index}" class="itemz flex_center_center" v-for="(item,index) in jqArrCv" :key="index"> 
              {{  item.name }}
          </div>
      </div>
      <el-table
        :data="CriminalInfoSelectList"
        border
        fit
        highlight-current-row
        height="660"
        stripe
        style="width: 90%;"
      >
        <el-table-column type="index" align="center" width="60" label="序号">
        </el-table-column>
        <el-table-column label="编号（省）" align="center" width="110">
          <template #default="scope">
            <span>{{ scope.row.provinceCode }}</span>
          </template>
        </el-table-column>
        <el-table-column label="姓名" align="center" width="120">
          <template #default="scope">
            <span>{{ scope.row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="身份证号" align="center">
          <template #default="scope">
            <span>{{ scope.row.account }}</span>
          </template>
        </el-table-column>
        <el-table-column label="处遇等级" align="center" width="80">
          <template #default="scope">
            <span>{{ scope.row.cylevel }}</span>
          </template>
        </el-table-column>
        <el-table-column label="入监日期" align="center">
          <template #default="scope">
            <span>{{ scope.row.rjrq }}</span>
          </template>
        </el-table-column>
        <el-table-column label="刑起刑止" align="center">
          <template #default="scope">
            <span>{{ scope.row.qr }} - </span>
            <span v-if="scope.row.zr != 'NaN-aN-aN'">{{ scope.row.zr }}</span>
            <span v-else>无期</span>
          </template>
        </el-table-column>
        <el-table-column label="刑期" align="center">
          <template #default="scope">
            <span>{{ scope.row.xq }}</span>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="罪名" align="center">
          <template #default="scope">
            <span>{{ scope.row.zm }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="example-pagination-block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next,total"
        :total="total"
      />
    </div>
  </div>
</template>

<script setup>
import http from "@/utils/api";
import {
  Search,
  Share,
  Upload,
  TakeawayBox,
  Refresh,
  Collection,
  Plus,
  Loading,
  FolderDelete,
  Back,
} from "@element-plus/icons-vue";
import {
  ref,
  watch,
  onMounted,
  onBeforeUnmount,
  reactive,
  onBeforeMount,
  nextTick,
  onUnmounted,
} from "vue";
import { defineProps, defineEmits } from "vue";
const activeName = ref("普管级");

const props = defineProps({
  isCode: {
    type: String,
    default: "",
  },
  orgIds: {
    type: Object,
    default: {},
  },
  jqArr: {
    type: Array,
    default: [],
  },
});
let CriminalInfoSelectList = ref([]);
let CriminalInfoSelectText = ref("");
let searchName = ref("");

const selectValue = ref("");

const optionsS = ref([
  {
    id: "普管级",
    name: "普管级",
  },
  {
    id: "严管级",
    name: "严管级",
  },
  {
    id: "宽管级",
    name: "宽管级",
  },
  {
    id: "考察级",
    name: "考察级",
  },
]);

onBeforeMount(() => {});

let dateSfm = ref("");
let hour = ref("");
let daydata = ref("");
// 获取年月日 时
const getFormattedDateTime = () => {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, "0");
  const day = String(now.getDate()).padStart(2, "0");
  const hours = String(now.getHours()).padStart(2, "0");
  const minutes = String(now.getMinutes()).padStart(2, "0");
  const seconds = String(now.getSeconds()).padStart(2, "0");
  dateSfm.value = `${hours}:${minutes}:${seconds}`;
  hour.value = String(now.getHours()).padStart(2, "0");
  daydata.value = `${year}-${month}-${day}`;

  return `${year}-${month}-${day} ${hour.value}`;
};
const total = ref(0);
const page = ref(1);
const limit = ref(10);
const cylevelValue = ref('');

const handleSizeChange = (val) => {
  console.log(`${val} items per page`);
};
const handleCurrentChange = (val) => {
  page.value = val;
  getCriminalInfoSelect();
  console.log(`current page: ${val}`);
};
const getCriminalInfoSelect = async () => {
  let res = await http.zfpt.CriminalInfoSelect({
    page: page.value,
    limit: limit.value,
    criminalNo: "",
    name: searchName.value,
    state: props.isCode,
    // state: "jnzy,ljtq,jbfr,cjxd,jwzy,jwzx,jhzs,zcfr,zyfr,syfr",
    jsh: "",
    orgId: selectValue.value,
    cylevel:cylevelValue.value,
    "location": '',
    "joinDate": '',
  });
  if (res && res.code == 0) {
    CriminalInfoSelectList.value = res.data.data;
    total.value = res.data.total;
    CriminalInfoSelectText.value = "罪犯" + `(${res.data.data.length}人)`;
  }
};
let jqArrCv = ref([])
let isIndex = ref(0)
const btnClick = (item,index)=>{
  selectValue.value = item.id;
  isIndex.value = index;
  getCriminalInfoSelect()
}


watch(
  () => props.jqArr,
  (newValue, oldValue) => {
    if (newValue) {
      if (props.jqArr) {
        // optionsS.value = props.jqArr;
        // selectValue.value = optionsS.value[0].id;
        jqArrCv.value = JSON.parse(JSON.stringify(props.jqArr));
        let arr = [];
       arr = jqArrCv.value.filter((item) => item.name.includes("监区"));

       jqArrCv.value = arr;
       
        let allJq = jqArrCv.value.map((itz)=>itz.id)
        selectValue.value = allJq[0];

      }
      getFormattedDateTime();
      getCriminalInfoSelect();
    } else {
    }
  },
  {
    deep: true, // 深度监听
    immediate: true, // 立即触发回调
  }
);
</script>

<style scoped lang="scss">
.isAtv{
  background-color: rgb(4 110 250 / 27%) !important;
  font-weight: bold;
}
/**
分页样式
 */
::v-deep .example-pagination-block {
  margin-top: 10px;
  margin-left: 230px;
  .el-pagination.is-background .btn-prev {
    background-color: #34517d3b;
    color: #ffffff;
  }
  .el-pagination.is-background .el-pager li {
    background-color: #34517d3b;
    color: #ffffff;
  }
  .el-pagination.is-background .btn-next {
    background-color: #34517d3b;
    color: #ffffff;
  }
  .el-pagination__total {
    color: #ffffff;
  }
  .el-pager li.is-active {
    background-color: #0768f9d3 !important;
  }
}
.btn_box{
  width: 10%;
  height: 100%;
  font-size: 16px;
  color: #fff;
  margin-right: 2px;
  .itemz{
    width: 100%;
    height: 30px;
    font-size: 14px;
    cursor: pointer;
    border: 1px solid rgb(5, 112, 146);
    // border-bottom: none;
    border-radius: 4px;
    margin-bottom: 2px;
  }

  .itemz:hover{
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1),
    1px 1px 1px rgba(255, 255, 255, 0.3),
     1px 1px 1vmax rgba(0, 0, 0, 0.1); 
  }
}
::v-deep .isTable .el-table {
  background-color: rgb(8, 32, 78) !important;
  .el-table tr {
    background-color: rgb(8, 32, 78) !important;
  }
  .cell {
    height: 50px;
    color: #fff;
    text-align: center;
    // border: 1px solid #ccc;
    background: rgb(8, 32, 78) !important;
    font-size: 12px;
    line-height: 50px;
  }
  .el-table__cell {
    border-color: 1px solid rgb(5, 112, 146);
    padding: 2px 0px !important;
    background: rgb(8, 32, 78) !important;
  }
  .el-table--fit .el-table__inner-wrapper:before {
    display: none !important;
  }
  .el-table th.el-table__cell.is-leaf {
    border: none !important;
  }
  --el-table-border-color: rgb(5, 112, 146);
}
.drawer_box {
  width: 100%;
  height: 100%;
  position: relative;
  padding: 0 20px;
  padding-top: 10px;
  .drawer_text {
    position: absolute;
    top: -23px;
    left: 2px;
    font-size: 18px;
  }
}
</style>
